// vim:sw=4:ai:aw
#include "Token.h"

#include <iostream>
using namespace std;

// To scan a string ...
#include <sstream>	// string-stream
using std::istringstream;
// e.g.
istringstream	iss( "a b <c|e>>f ; g h >i" );

// To scan from a file ...
#include <fstream>	// input file stream
using std::ifstream;
// e.g.
ifstream	ifs("test.sh");
// Or just use cin

// Send output to ...
ofstream	ofs("log.txt");
// Or just use cout


int main( int argc, char * argv[] )
{
    bool	more = true;
    Token	* tp;		// "huidige" token

    do {
	tp = nextToken( ifs );	// vraag eerst volgende token

	// vertel wat we gekregen hebben
	ofs << "token:" << tp->getType() << "\t";

	// kies een actie
	switch (tp->getType())
	{
	    case Token::END:
		more = false;
		ofs << "END"; break;
	    case Token::EOL:
		ofs << "NEWLINE"; break;
	    case Token::SEQUENCE:
		ofs << ";"; break;
	    case Token::PIPE:
		ofs << "|"; break;
	    case Token::INPUT:
		ofs << "<"; break;
	    case Token::OUTPUT:
		ofs << ">"; break;
	    case Token::APPEND:
		ofs << ">>"; break;
	    case Token::WORD:
		ofs << "WORD=|" << tp->getText() << "|";
		break;

	    default:	// missed something ?
		ofs << "?"<< tp->getText() << "?"; break;
	}
	ofs << endl;

	delete tp;	// gooi het token weer weg

    } while (more);
    return 0;
}

/*
#if	SH_LEVEL >= 1	// versatile
	    case Token::BACKGROUND:
		ofs << "&"; break;
#endif

#if	SH_LEVEL >= 2	// advanced
	    case Token::AND:
		ofs << "&&"; break;
	    case Token::OR:
		ofs << "||"; break;
	    case Token::SUBS:
		ofs << "("; break;
	    case Token::ENDS:
		ofs << ")"; break;
	    case Token::VAR:
		ofs << "VAR=|" << tp->getText() << "|";
		break;
	    case Token::EXPR:
		ofs << "EXPR=|" << tp->getText() << "|";
		break;
#endif

#if	SH_LEVEL >= 3 	// sh script
	    case Token::BQUOTE:
		ofs << "`"; break;
	    case Token::HERE:
		ofs << "<<"; break;
	    case Token::BREAK:
		ofs << ";;"; break;
#endif

#if	SH_LEVEL >= 4	// ksh/bash
	    case Token::EVAL:
		ofs << "$("; break;
#endif
*/
